package com.csun.cmny.provider.controller;

import com.csun.cmny.core.annotation.ValidateAnnotation;
import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.model.domain.OmcComments;
import com.csun.cmny.provider.model.domain.OmcLongRangeComments;
import com.csun.cmny.provider.model.dto.ServiceCommentDto;
import com.csun.cmny.provider.model.dto.comments.CommentsOtherDto;
import com.csun.cmny.provider.model.dto.comments.CommentsQueryDto;
import com.csun.cmny.provider.model.dto.comments.CommentsSaveDto;
import com.csun.cmny.provider.model.vo.comments.CommentsVo;
import com.csun.cmny.provider.model.vo.longRangeServiceOrder.LongRangeCommentsVo;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.OmcCommentsService;
import com.csun.cmny.provider.service.OmcLongRangeCommentsService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping(value = "/longRangeComments", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class OmcLongRangeCommentsController extends BaseController {

    @Resource
    private CmnyMessageSource cmnyMessageSource;

    @Resource
    private OmcLongRangeCommentsService commentsService;


    @ValidateAnnotation
    @ApiOperation(httpMethod = "POST", value = "首次评论")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Wrapper addChanner(@RequestBody @Valid CommentsSaveDto commentsSaveDto, BindingResult br) {



        int save = commentsService.addComments(commentsSaveDto,getLoginAuthDto());


        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),save);
    }

    @ValidateAnnotation
    @ApiOperation(httpMethod = "POST", value = "新增追评")
    @RequestMapping(value = "/addSo", method = RequestMethod.POST)
    public Wrapper addSo(@RequestBody @Valid CommentsOtherDto commentsOtherDto, BindingResult br) {


        OmcLongRangeComments omcComments = new OmcLongRangeComments();

        BeanUtils.copyProperties(commentsOtherDto,omcComments);


        int update = commentsService.update(omcComments);


        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),update);
    }

    /*
     * 服务人员查看评论
     * */
   /* @PostMapping(value = "/listComments")
    public Wrapper listComplaint(@RequestBody ServiceCommentDto serviceCommentDto){
        serviceCommentDto.setUserId(getLoginAuthDto().getUserId());
        PageInfo pageInfo=commentsService.listComments(serviceCommentDto);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success",null),pageInfo);
    }
*/

    @ValidateAnnotation
    @ApiOperation(httpMethod = "POST", value = "查看评论")
    @RequestMapping(value = "/select", method = RequestMethod.POST)
    public Wrapper select(@RequestBody @Valid CommentsQueryDto commentsQueryDto) {

        commentsQueryDto.setGroupId(getLoginAuthDto().getGroupId());

        List<LongRangeCommentsVo> list=commentsService.selectComments(commentsQueryDto);


        PageInfo<LongRangeCommentsVo> pageInfo = new PageInfo<>(list);


        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),pageInfo);
    }

   /* @ValidateAnnotation
    @ApiOperation(httpMethod = "POST", value = "医生查看自己的")
    @RequestMapping(value = "/selectBySpecialist", method = RequestMethod.POST)
    public Wrapper selectBySpecialist(@RequestBody @Valid CommentsQueryDto commentsQueryDto) {

        commentsQueryDto.setGroupId(getLoginAuthDto().getGroupId());

        List<LongRangeCommentsVo> list=commentsService.selectComments(commentsQueryDto);


        PageInfo<LongRangeCommentsVo> pageInfo = new PageInfo<>(list);


        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),pageInfo);
    }*/
}
